from itertools import product
from typing import Union, Dict

from flask import Flask, request
from flask import render_template
# 调用自定义模块中的函数
from research import researchletters
from timetable import table

# Flask:中央登记中心
app = Flask(__name__)

# 【Flask】(https://dormousehole.readthedocs.io/en/latest/quickstart.html#id10)
# 【HTMl】(https://www.w3school.com.cn/html/index.asp)
# 【jinja2】(https://palletsprojects.com/p/jinja/)

# 1. 路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
# 1.1 url: 相对于：http://127.0.0.1：5000的相对路径
# 1.2 methods:【GET】【POST】
# 2. 视图函数：
# 2.1 函数过程决定了你操作的方法（实现的功能），例如 if elif else for while ...
# 2.2 return：返回数据内容，text文本，HTML文件（模板渲染），JSON文件等

# 【GET】
@app.route('/',methods=['GET'])
def index():
    return render_template('index.html')

@app.route('/login',methods=['GET','POST'])
def login():
    return render_template('login.html')

@app.route('/name', methods=['GET'])
def name():
    return render_template('result_name.html')

@app.route('/shopping',methods=['GET'])
def shopping():
    return render_template('shopping.html')

@app.route('/shoppingcart',methods=['GET'])
def shoppingcart():
    return render_template('shoppingcart.html')


@app.route('/input_time', methods=['GET'])
def input_time():
    return render_template('input_time.html')


@app.route('/classtable', methods=['GET'])
def classtable():
    return render_template('classtable.html')

@app.route('/shopping_over', methods=['GET'])
def shopping_over():
    return render_template('shopping_over.html')

# 【POST】实现用户输入，点击提交，将数据提交到 /result
@app.route('/result_name',methods=['POST'])
def result_name():

    py_firstname = request.form['firstname']
    py_lastname = request.form['lastname']
    py_fullname = py_firstname.title()+' '+py_lastname.title()

    return render_template('result_name.html',
                           fullname=py_fullname,
                           )



@app.route('/word_result', methods=['POST','GET'])
def word_result():
    py_word = request.form['word']
    py_vowels = request.form['vowels']
    py_found = researchletters(py_vowels, py_word)
    return render_template('word_result.html',
                           found=py_found)


@app.route('/class_over',methods=['POST'])
def class_over():
    py_week = request.form['week']
    py_hour = request.form['hour']
    py_minute = request.form['minute']
    py_time = int(py_hour + py_minute)
    py_class = table(py_week, py_time)
    return render_template('class_over.html',
                           timetables=py_class,
                           hourtime=py_hour,
                           minutetime=py_minute)







if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000, debug=True)
